<%-- 
    Document   : createmessage
    Created on : Dec 2, 2013, 10:53:44 AM
    Author     : Tùng
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <link type="text/css" href="css/manage.css" rel="stylesheet">
        <link type="text/css" href="css/bootstrap.css" rel="stylesheet">
        <link type="text/css" href="css/index.css" rel="stylesheet">
        <link type="text/css" href="css/table.css" rel="stylesheet">
        <link type="text/css" href="css/blue.css" rel="stylesheet">

        <script type="text/javascript" src="js/modernizr.min.js"></script>
        <script type="text/javascript" src="js/raphael.js"></script>
        <script type="text/javascript" src="js/popup.js"></script>
        <script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
        <script type="text/javascript" src="js/analytics.js"></script>
        <script type="text/javascript" src="js/jquery-ui-1.10.3.custom.min.js"></script>
        <script type="text/javascript" src="js/underscore-min.js"></script>
        <script type="text/javascript" src="js/backbone-min.js"></script>
        <script type="text/javascript" src="js/bootstrap.min.js"></script>
        <script type="text/javascript" src="js/transition.js"></script>
        <script type="text/javascript" src="js/all.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
        <script type="text/javascript" src="js/6a4ae20ef44d.js"></script>
        <script src="js/table.js" type="text/javascript"></script>

        <title>Message Page</title>
        <c:if test="${empty sessionScope.ACCOUNT}">
            <c:redirect url="login.jsp"/>
        </c:if>
        <c:if test="${not empty sessionScope.CREATEMESSAGE}">
            <script type="text/javascript">
                $(function popuptracking() {
                    $("#dialog-modal").dialog({
                        minHeight: 200,
                        minWidth: 400,
                        modal: true,
                        title: "Create Message",
                        close: function(){
                            $("#main1").removeClass("ui-widget-overlay ui-front");
                        }
                    });

                    $("#main1").addClass("ui-widget-overlay ui-front");
                });
            </script>
        </c:if>
    </head>

    <body>
        <div id="main1">
            <div id="fixed-header" class="navbar-fixed-top row">
                <div id="menu" class="row">
                    <div id="menu-inner">
                        <div id="messages"></div>
                        <div id="menu-left" class="col-5">
                            <div id="dd-left" class="col-1 text-left">
                                <a data-toggle="dropdown" style="margin-top:20px" class="btn btn-disabled dropdown-toggle"><i class="icon-menu"></i></a>
                                <ul aria-labelledby="dLabel" role="menu" class="dropdown-menu">
                                    <li class="caret-up"></li>
                                    <li> <a href="CollectionController?btAction=LoadAllCollection">Collection</a></li>
                                    <li><a href="index.jsp">Search Products</a></li>
                                    <li><a href="ManageProductController?btAction=ShowTrackedProduct">Your Products</a></li>
                                    <li><a href="FeedbackController?btAction=ShowFeedback">Feedback</a></li>
                                    <li>______________________</li>
                                    <li> &nbsp;&nbsp;&nbsp;Member System</li>
                                </ul>
                            </div>
                            <div class="col-2 hiw">
                                <a href="home.jsp">Home</a>
                            </div>
                        </div>
                        <div class="col-2 text-center">
                            <img src="Images/PRTS.png" style="height: 80px"/>
                        </div>
                        <div id="menu-right" class="col-5">
                            <c:if test="${not empty sessionScope.ACCOUNT}">
                                <div id="dd-right">
                                    <a href="#" data-toggle="dropdown" class="dropdown-toggle">
                                        <span id="username-outer">
                                            <span id="username">${sessionScope.ACCOUNT.emailAddress}</span>
                                        </span>
                                        <span class="caret"></span>
                                    </a>
                                    <ul aria-labelledby="dLabel" role="menu" class="dropdown-menu">
                                        <li class="caret-up"></li>
                                        <li>
                                            <a id="profile" href="AccountController?action=updateAccountDetail">
                                                Account Preferences
                                            </a>
                                        </li>
                                        <c:if test="${sessionScope.ACCOUNT.role.roleID != 3}">
                                            <li>
                                                <a href="AdminController?btAction=LoadPage">Admin System</a>
                                            </li>
                                        </c:if>
                                        <li>
                                            <a id="history" href="MessageController?btAction=LoadReceivedMessage">
                                                Message
                                            </a>
                                        </li>
                                        <li>
                                            <a id="logout" href="HomeController?btAction=logout">
                                                Logout
                                            </a>
                                        </li>
                                    </ul>
                                </div>
                                <div class="pull-right ">
                                    <a href="ManageProductController?btAction=ShowTrackedProduct">My Finds</a>
                                </div>
                            </c:if>
                        </div>
                    </div>
                </div>

                <div id="tools-wrapper" class="visible" style="top: 85px">
                    <div class="row" id="sub-menu">
                        <div id="sub-menu-inner">
                            <div class="col-11">
                                Message Management <br/>
                                <a href="MessageController?btAction=CreateNewMessage">Create New Message</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="MessageController?btAction=LoadReceivedMessage">Load Received Message</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="MessageController?btAction=LoadSendMessage">Load Sent Message</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div id="content-wrapper" style="margin-top: -15px;">
                <div class="row products private-finds">
                    <div class="grid-container" style="width: 95%;">
                        <ul class="col-12 grid-view">
                            <br/>
                            <br/>
                            <h3 style="color:red" align="center">${REPLYMESSAGEERROR}${SENDMESSAGEERROR}${READSEERR}${DELETESEERR}</h3>
                            <h3 align="center">${SENDMESSAGESUCESS} ${REPLYMESSAGESUCESS}${DELETESEMESS}</h3>
                            <br/>

                            <c:if test="${not empty sessionScope.READSEMESS}">
                                <c:set var="readsemess" value="${sessionScope.READSEMESS}"/>
                                <table class="table table-hover">
                                    <thead>
                                        <tr>
                                            <th width="94%">
                                                To ${readsemess.sentTo}  &nbsp;&nbsp; &nbsp;&nbsp;</th>
                                            <th align="right"><a href="MessageController?btAction=CloseSentMessage"><img src="Images/close.png" /></a></th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                            <td><font style="display: block">Subject: ${readsemess.subject} </font> sent on ${readsemess.seDate}</td>
                                        </tr>
                                        <tr>
                                            <td><textarea rows="10" readonly>${readsemess.seContent}</textarea></td>
                                        </tr>
                                    </tbody>
                                </table>

                            </c:if>
                            <br/>

                            <c:set var="sentmess" value="${sessionScope.SENTMESS}"/>
                            <c:if test="${not empty sentmess}">
                                <table class="table table-hover example table-autosort table-autofilter table-autopage:10 table-stripeclass:alternate table-page-number:t1page table-page-count:t1pages table-filtered-rowcount:t1filtercount table-rowcount:t1allcount" >
                                    <thead>
                                        <tr>
                                            <th width="30"></th>
                                            <th class="table-sortable:default">Sent To</th>
                                            <th class="table-sortable:default">Subject</th>
                                            <th class="table-sortable:default">Sent On</th>
                                            <th width="30"></th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <c:forEach var="rows" items="${sentmess}">
                                            <tr>
                                                <td>
                                                </td>
                                                <td>&nbsp;${rows.sentTo}</td>
                                                <td>
                                                    <c:url var="read" value="MessageController">
                                                        <c:param name="btAction" value="readSeMess"/>
                                                        <c:param name="readSeMessageID" value="${rows.sentID}"/>
                                                    </c:url>
                                                    <a href="${read}">${rows.subject}</a>
                                                </td>
                                                <td>&nbsp;${rows.seDate}</td>
                                                <c:url var="delSeLink" value="MessageController">
                                                    <c:param name="btAction" value="deleteSeMess"/>
                                                    <c:param name="deleteSeMessageID" value="${rows.sentID}"/>
                                                </c:url>
                                                <td><a href="${delSeLink}"><img src="Images/trash.png" /></a></td>
                                            </tr>
                                        </c:forEach>
                                    </tbody>
                                    <tfoot>
                                        <tr>
                                            <c:forEach var="rows" items="${sentmess}">
                                                <c:set var="count" value="${count + 1}" />
                                            </c:forEach>
                                            <th colspan="6" align="center"><font>You have sent ${count} message(s) successfully</font></th>
                                        </tr>
                                        <tr>
                                            <td align="left" class="table-page:first"
                                                style="cursor: pointer;"><img src="Images/first.png" width="20" height="20"/></td>
                                            <td align="left" class="table-page:previous"
                                                style="cursor: pointer;"><img src="Images/previous.png" width="20" height="20"/></td>
                                            <td style="text-align: center;">Page <span
                                                    id="t1page"></span>&nbsp;of <span id="t1pages"></span>
                                            </td>
                                            <td align="right" class="table-page:next"
                                                style="cursor: pointer;"><img src="Images/next.png" width="20" height="20"/></td>
                                            <td align="right" class="table-page:last" style="cursor: pointer;"><img src="Images/last.png" width="20" height="20"/></td>
                                        </tr>
                                    </tfoot>
                                </table>
                            </c:if>
                            <c:if test="${empty sentmess}">
                                <h3 style="color: red">Sorry! You didn't send any message! <a href="MessageController?btAction=CreateNewMessage">Send now!</a></h3>
                            </c:if>
                        </ul>
                    </div>
                </div>
            </div>
        </div>

        <div id="dialog-modal" class="row top-inner" style="display: none; min-height: 100px;">
            <c:if test="${not empty sessionScope.CREATEMESSAGE}">
                <div class="login-bg">
                    <div class="form">
                        <div class="login-bg">
                            <form class="form-horizontal" id="login-form" method="post" action="MessageController">
                                <div class="form">
                                    <input type="text" placeholder="Send to email" name="txtReceivedEmail" maxlength="75" id="id_email" required />
                                    <input type="text" placeholder="Subject" name="txtSubject" maxlength="75" required id="txtSubject"/>
                                    <textarea rows="10" placeholder="Content" name="txtSendContent"></textarea>
                                </div>
                                <div id="lower-login" class="row">
                                    <div class="login-signup col-lg-6 col-md-4 col-sm-12 pull-left">
                                        <button name="btAction" type="submit" class="btn btn-primary btn-block" value="SendMessage"
                                                onclick="if ((txtSubject.value.length < 7)) {
                                                    alert('Subject must have length from 7 characters');
                                                    return false;
                                                }">Send</button>
                                    </div>
                                    <div class="login-signup col-lg-6 col-md-4 col-sm-12 pull-right">
                                        <button name="action" type="reset" class="btn btn-primary btn-block"
                                                >Clear</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </c:if>
        </div>
        <% session.removeAttribute("CREATEMESSAGE");%>
        <% session.removeAttribute("READSEERR");%>
        <% session.removeAttribute("DELETESEERR");%>
        <% session.removeAttribute("DELETESEMESS");%>
        <% session.removeAttribute("SENDMESSAGESUCESS");%>
        <% session.removeAttribute("SENDMESSAGEERROR");%>
        <% session.removeAttribute("REPLYMESSAGESUCESS");%>
        <% session.removeAttribute("REPLYMESSAGEERROR");%>
    </body>
</html>
